#include <stdio.h> 
#include <stdlib.h> 
#include <signal.h> 
#include <stddef.h> 
#include <sys/wait.h> 
#include <sys/ioctl.h> 
#include <sys/termios.h>

#include <string.h>   //memset 
#include <unistd.h>  //execel 
int main() 
{ 
    //printf("Hello world!\n"); 
    //return 0; 
    int status; 
    int cpid; 
    int ppid; 
    char buf[256]; 
    sigset_t blocked;

    ppid = getpid(); 
    if(!(cpid=fork())) 
    { 
        setpgid(0,0); 
        tcsetpgrp(0,cpid); 
        execl("/usr/bin/vi","vi",NULL); 
        exit(-1); 
    } 
    if(cpid < 0) 
        exit(-1); 
    setpgid(cpid,cpid); 
    tcsetpgrp(0,cpid); 
    waitpid(cpid,NULL,0); 
    tcsetpgrp(0,ppid);

    while(1) 
    { 
        memset(buf,0,256); 
        fgets(buf,256,stdin); 
        puts("ECHO: "); 
        puts(buf); 
        puts("\n"); 
        //sleep(1); 
    }

}
